/*
 * Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.greenrobot.daogenerator.gentest;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
import de.greenrobot.daogenerator.ToOne;

/**
 * Generates entities and DAOs for the example project DaoExample.
 * <p/>
 * Run it as a Java application (not Android).
 *
 * @author Markus
 */
public class ExampleDaoGenerator {

    public static void main(String[] args) throws Exception {
        Schema schema = new Schema(1000, "com.app.xinfadi.green_dao.model");
        schema.setDefaultJavaPackageDao("com.app.xinfadi.green_dao.dao");
//        addConfiguration(schema);
//        addGroup(schema);
//        addOptions(schema);
//        addProject(schema);
//        addQuestion(schema);
//        addRecord(schema);
        getProduct(schema);
        new DaoGenerator().generateAll(schema, "./app/src/main/java");
    }

    private static void getProduct(Schema schema) {
        Entity project = schema.addEntity("ProductBean");
        project.setTableName("T_Product");
        project.addLongProperty("_id").primaryKey().autoincrement();
        project.addStringProperty("ID");
        project.addStringProperty("NAME");
        project.addStringProperty("REAMRK");
        project.addStringProperty("PARENT_ID");
        project.addStringProperty("ICON");


    }

//    /**
//     * 勘察任务
//     *
//     * @param schema
//     */
//    private static void addProject(Schema schema) {
//        Entity project = schema.addEntity("Project");
//        project.setTableName("T_PROJECT");
//        project.addLongProperty("id").primaryKey().autoincrement();
//        project.addStringProperty("no");
//        project.addStringProperty("type");
//        project.addShortProperty("entrustCompany").columnName("entrust_Company");//委托公司
//        project.addStringProperty("entrustDepartment").columnName("entrust_Department");//委托部门
//        project.addStringProperty("entrustPerson").columnName("entrust_Person");//委托人
//        project.addStringProperty("entrustPhone").columnName("entrust_Phone");//委托人电话
//        project.addStringProperty("province");//所在省
//        project.addStringProperty("city");//所在市
//        project.addStringProperty("area");//所在行政区
//        project.addStringProperty("communityName").columnName("community_Name");//所在小区
//        project.addStringProperty("buildingName").columnName("building_Name");//楼栋名称
//        project.addStringProperty("floor");//楼层
//        project.addStringProperty("address");//地址
//        project.addStringProperty("square");//建筑面积
//        project.addStringProperty("owner");//业主
//        project.addStringProperty("ownerPhone").columnName("owner_Phone");//业主电话
//        project.addStringProperty("goalName").columnName("goal_Name");//目标名称
//        project.addIntProperty("status");//项目状态
//        project.addLongProperty("receiveUser").columnName("receive_User");//领取人
//        project.addStringProperty("emergencyDegree").columnName("emergency_Degree");//紧急程度
//        project.addLongProperty("configuration");//使用配置
//        project.addLongProperty("createUser").columnName("create_User");//创建用户
//        project.addDateProperty("createDate").columnName("create_Date");//创建时间
//        project.addLongProperty("updateUser").columnName("update_User");//更新用户
//        project.addDateProperty("updateDate").columnName("update_Date");//创建时间
//        project.addLongProperty("fees").columnName("fees_id");//更新用户
//        project.addIntProperty("del");
//        project.addDateProperty("receiveDate").columnName("receive_date");//创建时间
//        project.addDateProperty("completeDate").columnName("complete_date");//创建时间
//        project.addBooleanProperty("isHaveRecord").columnName("is_have_record");//是否存有答案
//    }
//
//    /**
//     * 配置表
//     *
//     * @param schema
//     */
//    private static void addConfiguration(Schema schema) {
//        Entity configuration = schema.addEntity("Configuration");
//        configuration.setTableName("T_Configuration");
//        configuration.addLongProperty("id").primaryKey().autoincrement();
//        configuration.addStringProperty("name");
//        configuration.addLongProperty("type");
//        configuration.addIntProperty("version");
//        configuration.addLongProperty("createUser").columnName("create_User");
//        configuration.addDateProperty("createDate").columnName("create_Date");
//        configuration.addIntProperty("isDefault").columnName("is_default");
//        configuration.addIntProperty("del");
//    }
//
//    /**
//     * 分组信息
//     *
//     * @param schema
//     */
//    private static void addGroup(Schema schema) {
//        Entity group = schema.addEntity("Group");
//        group.setTableName("T_GROUP");
//        group.addLongProperty("id").primaryKey().autoincrement();
//        group.addLongProperty("configuration");
//        group.addStringProperty("name");
//        group.addIntProperty("index").columnName("indexs");
//        group.addLongProperty("user").columnName("user_id");
//        group.addDateProperty("createdate");
//        group.addIntProperty("del");
//    }
//
//    /**
//     * 题目
//     *
//     * @param schema
//     */
//    private static void addQuestion(Schema schema) {
//        Entity question = schema.addEntity("Question");
//        question.setTableName("T_QUESTION");
//        question.addLongProperty("id").primaryKey().autoincrement();
//        question.addStringProperty("name");
//        question.addLongProperty("groupId").columnName("group_id");
//        question.addStringProperty("type");
//        question.addIntProperty("index").columnName("indexs");
//        question.addIntProperty("required");
//        question.addIntProperty("score");
//        question.addIntProperty("del");
//    }
//
//    /**
//     * 某一道题里的选项
//     *
//     * @param schema
//     */
//    private static void addOptions(Schema schema) {
//        Entity options = schema.addEntity("Options");
//        options.setTableName("T_OPTIONS");
//        options.addLongProperty("id").primaryKey().autoincrement();
//        options.addLongProperty("questionId").columnName("question_id");
//        options.addStringProperty("optionCode").columnName("option_code");
//        options.addStringProperty("contents");
//        options.addIntProperty("isCorrect").columnName("correct");
//        options.addIntProperty("score");
//        options.addIntProperty("del");
//    }
//
//    /**
//     * 答案
//     *
//     * @param schema
//     */
//    private static void addRecord(Schema schema) {
//        Entity record = schema.addEntity("Record");
//        record.setTableName("T_RECORD");
//        record.addLongProperty("id").primaryKey().autoincrement();
//        record.addLongProperty("configuration").columnName("configuration_id");
//        record.addLongProperty("project_id");//对用 服务器数据库的no
//        record.addLongProperty("question").columnName("question_id");
//        record.addStringProperty("type");
////        record.addStringProperty("choose");
//        record.addStringProperty("answer");
////        record.addStringProperty("image");
//        Property gpsIdProperty = record.addLongProperty("gps_id").getProperty();
//        record.addIntProperty("correct");
//        record.addIntProperty("score");
//        record.addLongProperty("user").columnName("user_id");
//        record.addDateProperty("answerDate").columnName("answer_date");
//        record.addBooleanProperty("selectBoolean");//是否选择
//
//        //多选答案
//        Entity chooses = schema.addEntity("Chooses");
//        chooses.addIdProperty();
//        chooses.setTableName("T_CHOOSES");
//        Property choose = chooses.addStringProperty("choose").getProperty();
//        Property chooses_record_id = chooses.addLongProperty("record_id").notNull().getProperty();
//        chooses.addLongProperty("no");//第几个答案
//        chooses.addToOne(record, chooses_record_id);
//
//        ToMany recordToChooses = record.addToMany(chooses, chooses_record_id);
//        recordToChooses.setName("chooses");
////        chooesToRecord.orderAsc(choose);
//
//        //图片列表
//        Entity images = schema.addEntity("Images");
//        images.addIdProperty();
//        images.setTableName("T_IMAGE");
//        Property image_file_position = images.addStringProperty("image_file_position").getProperty();
//        images.addStringProperty("image_file_url");
//        images.addLongProperty("no");//该道题 第几个图片
//        Property image_record_id = images.addLongProperty("record_id").notNull().getProperty();
//        images.addToOne(record, image_record_id);
//
//        ToMany recordToImages = record.addToMany(images, image_record_id);
//        recordToImages.setName("images");
////        imagesToRecord.orderAsc();
//
//        Entity gps = schema.addEntity("Gps");
//        gps.setTableName("T_GPS");
//        gps.addIdProperty();
//        gps.addDoubleProperty("latitude");
//        gps.addDoubleProperty("longitude");
//        Property gps_record_id = gps.addLongProperty("record_id").notNull().getProperty();
//        gps.addToOne(record, gps_record_id);
//
//        record.addToOne(gps, gpsIdProperty);
//
//    }
//    private static void addNote(Schema schema) {
//        Entity note = schema.addEntity("Note");
//        note.addIdProperty();
//        note.addStringProperty("text").notNull();
//        note.addStringProperty("comment");
//        note.addDateProperty("date");
//    }

//    private static void addCustomerOrder(Schema schema) {
//        Entity customer = schema.addEntity("Customer");
//        customer.addIdProperty();
//        customer.addStringProperty("name").notNull();
//
//        Entity order = schema.addEntity("Order");
//        order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
//        order.addIdProperty();
//        Property orderDate = order.addDateProperty("date").getProperty();
//        Property customerId = order.addLongProperty("customerId").notNull().getProperty();
//        order.addToOne(customer, customerId);
//
//        ToMany customerToOrders = customer.addToMany(order, customerId);
//        customerToOrders.setName("orders");
//        customerToOrders.orderAsc(orderDate);
//    }

}
